<template>
  <div>
    <Teleport v-if="isMounted" to="#title-left-teleport-from-child">
      <div class="title">
        <a-space>
          <a-button size="small" @click="() => router.push({ name: 'Blacklist Index' })">
            <template #icon>
              <e-icon type="Aright" />
            </template>
          </a-button>
          <!--<a-tag class="history-tag">Existing</a-tag>-->
          <span class="client-name">{{ name }}</span>
        </a-space>
      </div>
    </Teleport>
    <e-container style="min-height: 500px">
      <div class="table">
        <a-row>
          <a-col :span="24" class="cell header">Blacklist History</a-col>
        </a-row>
        <a-row>
          <a-col :span="4" class="cell field">Time</a-col>
          <a-col :span="4" class="cell field">Operator</a-col>
          <a-col :span="4" class="cell field">Operation</a-col>
          <a-col :span="12" class="cell field">Reason</a-col>
        </a-row>
        <a-row v-for="(record, index) in records" :key="index">
          <a-col :span="4" class="cell">{{ record.createOn }}</a-col>
          <a-col :span="4" class="cell">{{ record.displayName }}</a-col>
          <a-col :span="4" class="cell">{{ record.historyTypeName }}</a-col>
          <a-col :span="12" class="cell">{{ record.reason }}</a-col>
        </a-row>
        <e-empty v-if="records.length === 0" centered />
      </div>
    </e-container>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import EContainer from '@/components/EContainer.vue'
import EEmpty from '@/components/EEmpty.vue'
import Blacklist from '@/api/blacklist.js'
const isMounted = ref(false)
const router = useRouter()
const route = useRoute()
const { id, name } = route.params
onMounted(() => {
  isMounted.value = true
})
const records = ref([])
Blacklist.detail(id).then(({ data }) => {
  records.value = data
})
</script>

<style lang="less" scoped>
.title {
  min-width: 500px;
  .history-tag {
    height: 24px;
    color: #818d9f;
    font-weight: normal;
    border-color: #dcdee7;
    background-color: #f6f6fb;
  }
  .client-name {
    font-weight: bold;
    font-size: 16px;
  }
}
@border: 1px solid @lighter-gray;
.table {
  border: @border;
  .cell {
    padding: 10px 14px;
    border-bottom: @border;
    border-right: @border;
    &:last-child {
      border-right: none;
    }
    &.field {
      background-color: @milk;
      color: @text-gray;
    }
    &.header {
      background-color: @bg-color;
      color: #808c9f;
      font-weight: bold;
    }
  }
  .ant-row:last-child {
    .cell {
      border-bottom: none;
    }
  }
  .ant-tag {
    background-color: @phase-default;
    border: none;
    padding: 1px 12px;
    font-size: 14px;
    .e-icon {
      color: @primary-color !important;
      cursor: pointer;
    }
  }
}
</style>

<route lang="yaml">
name: Blacklist Operation History
path: /blacklist/history/:id/:name
meta:
  title: Blacklist Operation History
  roles: isPrimaryCSO
</route>
